Forum:Template argument looping extension
I've been thinking about this for a while in relation to custom tabitem templates, but seeing Timeroot's recent change to 1x I think it might have more general applicability. It would be convenient to have a way of looping through template arguments. Example syntax: the new 1x could be } } }}} where #shiftloop would be provided by a new extension, the first argument would be the number of template arguments to hold steady, and it would repeatedly output the second argument and then shift the template arguments after the constant set left one while there were some. E.g. would emit a and then enter the shiftloop with current template arguments }=a, }=-, }=b, }=c; there are more than 2 arguments, so it emits } } is -b and then shifts the arguments to }=a, }=-, }=c; there are more than 2 arguments, so it emits -c and shifts to }=a, }=-; there are only 2 arguments, so it ends. Developing this would be a fairly major project for me, because I'd have to learn how to set up a test environment for it plus a fair bit of wiki internals. Therefore before starting I want to make sure that it wouldn't be a waste of time. People who write/edit templates, is this suitable for you to use? Have I explained it well? Is it powerful enough, or does it need extra complications to allow you to shift more than one argument at a time? (If so, where the number of non-constant arguments is less than the shift size they would be ignored). Is it worth the effort, or would we be better off trying to set up and use one of the existing, more powerful, extensions (Extensions:Variables with either Extension:Loops or Extension:Control Structure Functions; or Winter)? Does anyone know enough about the technical side of MediaWiki to know the pros and cons of using parser functions as above vs custom tags (e.g. } })? CompScis, can you see a better way of doing it, bearing in mind that my main goal is that it be more intuitive for non-programmers than a full-blown programming language, and that I consider it an advantage that it's not Turing-powerful and so doesn't allow a malicious script to tie up lots of resources in an infinite loop? OrbFu 11:48, 26 February 2009 (UTC) :Addendum: shiftloop would restore the arguments to their previous values when it finished, so it would be possible e.g. to loop through them twice. OrbFu 12:14, 26 February 2009 (UTC) ::Sounds very powerful. But, I still don't quite understand how it would work. Did you mean to say the the code for 1x would be: :: } }| }}} ::I can't tell. And you say this would stop resource-hogging infinite loops... what's to stop someone from writing :: }}}} ::If I understand this correctly, it would cycle through every single number from 1 to 1000000000000000000000000. Or am I interpreting this wrong? It does sound very useful, however. Timeroot Talk • • 16:21, 26 February 2009 (UTC) :::To the first: yes. To the second: no, that's not how it works. The number of times the loop is iterated is equal to the number of (unnamed) arguments passed to the template less the first parameter of #shiftloop, so would do nothing at all unless you pass at least 100000001 template arguments. 1x is an example of a loop which wants to keep some of its parameters unshifted (as otherwise it needs to store them, which means Extension:Variables is needed anyway). I suppose an alternative way of doing that particular example without the ability to "hold" arguments would be to change the parameters slightly so that the separator is a named argument and then write ::: } }| }|}}}} :::I'm not sure which is more intuitive, but I incline towards the hold functionality, which includes the other as a subset anyway. :::The example you give does raise an interesting question: how should nesting work? As things stand, i.e. without specifying any special behaviour, }}}}} called with three arguments a,b,c would emit abcbcc - probably not very helpful. It might be worthwhile to make a nested shiftloop give an error as a precaution against super-linear time operation. I don't think we lose much. OrbFu 17:32, 26 February 2009 (UTC)